<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>生产计划</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
		 
		 /* 防止下拉框的下拉列表被隐藏---必须设置--- */        
		.layui-table-cell {            overflow: visible !important;        } 
		/* 使得下拉框与单元格刚好合适 */       
		/* td .layui-form-select{
			margin-top: 50px;
			margin-left: -15px;
			margin-right: -15px;
		}   */   
	</style>
	
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
    	<input class="layui-input" name="searchTime" id="searchTime" placeholder="请输入制单时间" style="display: inline; width: 45%">
        <input class="layui-input" name="keyword" id="keyword" placeholder="请输入生产订单号" autocomplete="off" style="display: inline; width: 45%">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table><br/>
<table class="layui-hide" id="detail" lay-filter="detail"></table>

<div id="addDivID" hidden="hidden">
	<form class="layui-form" id="addFormID">
		<button class="layui-btn layui-btn-blue" lay-submit lay-filter="addForm" style="margin-left:160px; margin-bottom: 20px">立即提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>
	</form>
</div>

<script type="text/html" id="toolbar">
</script>
<!-- 	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="choose" id="test1"><i class="layui-icon layui-icon-upload" >  导入</i></button>
	</div> -->
          
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
 <script type="text/html" id="selectGxmc" >    
	<select name='jtcyGxmc' lay-verify='' lay-search=''>
        <option value=""></option>
        <option value="父子">父子</option>
        <option value="母子">母子</option>
        <option value="姐弟">姐弟</option>
        <option value="弟弟">弟弟</option>
    </select>
</script>
 
 
 
<script type="text/javascript">
	layui.use(['table','layer','upload','form','laydate'], function(){
		var table = layui.table;
		var layer = layui.layer;
		var laydate = layui.laydate;
	    var form = layui.form;
		
		var $ = layui.jquery, active = {
			reload:function () {
				var searchTime = $("#searchTime").val();
				var keyword = $("#keyword").val();
				console.log(searchTime + ',' + keyword)
				table.reload('contenttable',{
					method:'get',
					where:{"mtime":searchTime, "plannumber":keyword}
				});
			}
		}
		$('.layui-btn').on('click', function(){
	        var type = $(this).data('type');
	        active[type] ? active[type].call(this) : '';
	    });
		table.render({
		    elem: '#tableList'
		    ,url:'${pageContext.request.contextPath }/plan/planList.do' 
		    ,toolbar: '#toolbar'
		    ,title: '生产计划信息'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
		      {type: 'checkbox', fixed: 'left'},
		      /* {field:'id', title:'ID' }, */
		      {field:'plannumber', title:'生产订单号', fixed: 'left', unresize: true, sort: true},
		      {field:'department', title:'部门'},
		      {field:'mtime', title:'制单日期'},
		    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
		
		table.render({
		    elem: '#detail'
		    ,url:'${pageContext.request.contextPath }/planDetail/planDetailList.do'
		    ,title: '生产计划详情'
		    ,id :'detailtable'
		    ,limits:[10,20,30]
		    ,cols: [[
		      {type: 'checkbox', fixed: 'left'},
		      {type: 'numbers', title: '行号', fixed: 'left', unresize: true},
		     /*  {field:'id', title:'ID' }, */
		      {field:'remark1', title:'产品编码'},
		      {field:'remark2', title:'产品名称'},
		      {field:'remark3', title:'产品规格'},
		      {field:'dtate', title:'状态'},
		      {field:'starttime', title:'开工日期'},
		      {field:'endtime', title:'完工日期'},
		      {field:'unit', title:'计量单位'},
		      {field:'num', title:'生产数量'},
		      {field:'remark5', title:'设备', edit: 'text'},
		      {field:'check', title:'质检'},
		      {field:'remark', title:'备注'},
		    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
	  
		//头工具栏事件
		table.on('toolbar(tableList)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
		    switch(obj.event){
			    case 'add':
			    	layer.open({
						type: 1 					//Page层类型
				  		,area: ['550px', '650px'] 	//宽  高
				  		,title: '新增'
				  		,shade: 0.6 				//遮罩透明度
				  		,maxmin: true 				//允许全屏最小化
				  		,anim: 1 					//0-6的动画形式，-1不开启
				  		,content: $("#addDivID")
				  		,end: function(){
				  			$("#addDivID").hide();
				  		}
					});
		      	break;
			    case 'delete':
		        	var data = checkStatus.data;
		        	var idArr = new Array();
		        	if(data.length==0){
		        		toastr.warning("请至少选择一条记录！");
		        	}
		        	for(var i=0;i<data.length;i++){
		        		alert(data[i].uid)
		        	}
		      	break;
		      	case 'select':
		      		console.log(obj)
		      	break;
		    };
		});
		
		 //监听行单击事件（单击事件为：rowDouble）
		  table.on('row(tableList)', function(obj){
		    var data = obj.data;
			table.reload('detailtable',{
				method:'get',
				where:{"remark4":data.id}
			});
		    
		    //标注选中样式
		    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		  });
		 
		  //监听单元格编辑    详情修改
		  table.on('edit(detail)', function(obj){
		    var value = obj.value //得到修改后的值
		    ,data = obj.data //得到所在行所有键值
		    ,field = obj.field; //得到字段
		   // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/plan/editRemark5.do',
		    	data: ""+field+"=" + value + "&id=" + data.id,
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("修改成功！");
		    		}else{
		    			toastr.warning("修改失败！");
		    		}
		    	}
		    })
		  });
	   
	  	//时间检索
	    laydate.render({
	      elem: '#searchTime',
	      format: 'yyyy-MM-dd'
	    });
	});
	toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>

<script>
layui.use(['element','upload'], function(){
  var $ = layui.jquery
  ,element = layui.element;
  upload = layui.upload;
  
  //指定允许上传的文件类型
  upload.render({
    elem: '#test1'
    ,url: '${pageContext.request.contextPath }/plan/uploadPlan.do'
    ,accept: 'file' //普通文件
    ,method: 'POST'
   	,field: "file" 
 	,before: function(obj){
 		layer.load();
    }
  ,done: function(res){//上传完毕回调
      layer.closeAll('loading');
      var result = '';

      for(var i=0; i<res.length; i++){
          result = result + res[i].nsrsbh+"="+res[i].container+"\n";
      }

      $("#result").html(result);
  }
  ,error: function(){//请求异常回调
      layer.closeAll('loading');
      layer.msg('网络异常，请稍后重试！');
  }
  });
});
</script>

</body>
</html>